package com.lxw.report.meta.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxw.report.meta.contract.BaseResponse;
import com.lxw.report.meta.contract.SysMenu.*;
import com.lxw.report.meta.contract.SysRole.*;
import com.lxw.report.meta.contract.SysUser.SysUserRoleCreateBatchRequest;
import com.lxw.report.meta.entity.Menu;
import com.lxw.report.meta.entity.Role;
import com.lxw.report.meta.service.ComplexService;

import com.lxw.report.meta.service.IRoleService;
import com.lxw.report.meta.vo.ResultVo;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api(tags = "角色管理")
@RestController
@RequestMapping ( "/role" )
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @Autowired
    private ComplexService complexService;

    @PostMapping("/listByUser")
    @ResponseBody
    public ResultVo<List<Role>> getListByUser(HttpServletRequest request) {
//        XxlSsoUser xxlUser = (XxlSsoUser) request.getAttribute(Conf.SSO_USER);
        List<Role> resultList = complexService.getRoleList(Long.parseLong(null));
        return new ResultVo(resultList);
    }

    @PostMapping("/addRoleMenuBatch")
    @ResponseBody
    public ResultVo addRoleMenuBatch(@Validated SysRoleMenuCreateBatchRequest createRequest, BindingResult bindingResult) {

        BaseResponse baseResponse = complexService.addRoleMenuBatch(createRequest);

        return ResultVo.success();
    }

    @PostMapping("/add")
    @ResponseBody
    public ResultVo add(HttpServletRequest request, @Validated SysRoleCreateRequest createRequest, BindingResult bindingResult) {
//
//        Role role=BeanUtil.copyProperties(createRequest,Role.class);
//        role.setCreatedBy(Long.parseLong(xxlUser.getUserid()));
//        if(roleService.save(role)){
//            return ResultVo.success();
//        }else{
//            return ResultVo.fail();
//        }

        return ResultVo.fail();
    }

    @PostMapping("/edit")
    @ResponseBody
    public ResultVo edit(HttpServletRequest request, @Validated SysRoleUpdateRequest updateRequest, BindingResult bindingResult) {
        return ResultVo.fail();
    }

    @PostMapping("/find")
    @ResponseBody
    public ResultVo<SysRoleFindResponse> find(SysRoleFindRequest findRequest) {
        SysRoleFindResponse response=new SysRoleFindResponse();

        return new ResultVo(response);
    }

    @PostMapping("/delete")
    @ResponseBody
    public ResultVo delete(@Validated SysRoleDeleteRequest deleteRequest, BindingResult bindingResult) {
        return ResultVo.fail();
    }
}